package cc.lj.internal.coupons.interfaces.facade;

import cc.lj.internal.api.coupons.dto.TicketPayRecordApiDTO;
import cc.lj.internal.api.coupons.dto.command.TicketPayRecordApiUpdateCommand;
import cc.lj.internal.api.coupons.dto.querty.TicketPayRecordApiQuery;
import cc.lj.internal.core.exception.SysExceptionEnum;
import cc.lj.internal.core.http.HttpResult;
import cc.lj.internal.coupons.application.service.TicketBatchAppService;
import cc.lj.internal.coupons.domain.ticket.model.vo.TicketPayRecordDO;
import cc.lj.internal.coupons.domain.ticket.service.ITicketPayRecordDomainService;
import cc.lj.internal.coupons.interfaces.dto.TicketBatchDTO;
import cc.lj.internal.coupons.interfaces.dto.convert.TicketPayRecordDTOConvertDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * 合同收券表接口
 * @author liangxifeng
 * @date 2022-01-12
 */
@RestController
@Slf4j
@Validated
@Api(tags = "合同收券表接口")
@RequestMapping("ticketPayRecord")
public class  TicketPayRecordController {

    @Resource(name = "ticketPayRecordDomainServiceImpl")
    private ITicketPayRecordDomainService recordDomainService;

    /**
     * 等值查询list
     */
    @PostMapping("/getList")
    @ApiOperation(value = "查询合同收券表list,无分页",notes = "错误码：无")
    public HttpResult<List<TicketPayRecordApiDTO>> getList(@Valid @RequestBody TicketPayRecordApiQuery recordApiQuery) {
        TicketPayRecordDO payRecordDO = TicketPayRecordDTOConvertDO.INSTANCE.convert(recordApiQuery);
        List<TicketPayRecordDO> payRecordDOList = recordDomainService.getList(payRecordDO);
        List<TicketPayRecordApiDTO> returnList = new ArrayList<>();
        for (TicketPayRecordDO ticketPayRecordDO : payRecordDOList) {
            returnList.add(TicketPayRecordDTOConvertDO.INSTANCE.convert(ticketPayRecordDO));
        }
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),returnList);
    }

    /**
     * 通过主键修改
     * @param payRecordApiUpdateCommand
     * @return 影响行数
     */
    @PostMapping("/updateById")
    @ApiOperation(value = "通过主键修改合同收券表数据",notes = "错误码：1005001055")
    public HttpResult<Integer> updateById(@RequestBody TicketPayRecordApiUpdateCommand payRecordApiUpdateCommand) {
        TicketPayRecordDO payRecordDO = TicketPayRecordDTOConvertDO.INSTANCE.convert(payRecordApiUpdateCommand);
        Integer rows = recordDomainService.updateById(payRecordDO);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),rows);
    }
}
